// var i;
// var $eventManager = require("./EventManager");
// var $module_WareHouse_UIBindings = require("./Module_WareHouse_UIBindings");
// var $aIControl = require("./AIControl");
// var $const_Common = require("./Const_Common");
// var $guideControl = require("./GuideControl");
// var $redPointControl = require("./RedPointControl");
// var $evenType = require("./EvenType");
// var $playerDataManager = require("./PlayerDataManager");
// var $excel = require("./Excel");
// var $logic_ChildMoveEvent = require("./Logic_ChildMoveEvent");
// var $const_Hall = require("./Const_Hall");
// var $hallGlobalVariable = require("./HallGlobalVariable");
// var $item_Bag_EquipItem = require("./Item_Bag_EquipItem");
// var $uI_Hall = require("./UI_Hall");
// var $baseModule = require("./BaseModule");
// var I = cc._decorator;
// var M = I.ccclass;
// var E = I.property;
// var x = I.inspector;
// var C = (function (t) {
//     function o() {
//         var e = (null !== t && t.apply(this, arguments)) || this;
//         e.auto_ui = null;
//         e.equipItem = null;
//         e.dragnode = null;
//         return e;
//     }
//     __extends(o, t);
//     o.prototype.onLoad = function () {
//         $eventManager.EventMgr.addEventListener($evenType.EVENT_TYPE.HallBagShowDrag, this.ShowDrag, this);
//         $eventManager.EventMgr.addEventListener($evenType.EVENT_TYPE.HallBagRemoveId, this.RemoveHero, this);
//         $eventManager.EventMgr.addEventListener($evenType.EVENT_TYPE.HallResetBag, this.ResetThis, this);
//         $eventManager.EventMgr.addEventListener($evenType.EVENT_TYPE.ResetWareHouseAI, this.EventResetAI, this);
//     };
//     o.prototype.onDestroy = function () {
//         t.prototype.onDestroy.call(this);
//         $eventManager.EventMgr.rmEventListener($evenType.EVENT_TYPE.HallBagShowDrag, this.ShowDrag, this);
//         $eventManager.EventMgr.rmEventListener($evenType.EVENT_TYPE.HallBagRemoveId, this.RemoveHero, this);
//         $eventManager.EventMgr.rmEventListener($evenType.EVENT_TYPE.HallResetBag, this.ResetThis, this);
//         $eventManager.EventMgr.rmEventListener($evenType.EVENT_TYPE.ResetWareHouseAI, this.EventResetAI, this);
//     };
//     o.prototype.show = function () {
//         var e = this;
//         this.StartSet();
//         this.scheduleOnce(function () {
//             if (
//                 $playerDataManager.PlayerDataMgr.GetGuideIndexByTaskName($const_Common.GuideName.仓库升级) ==
//                 $const_Common.UpEquipLevelGuideIndex.引导点击仓库水果2
//             ) {
//                 var t = e.auto_ui.node_dressupFather.children[0];
//                 if (t) {
//                     var o = t.convertToWorldSpaceAR(cc.v2(0, 0));
//                     var n = cc.size(t.width, t.height);
//                     $guideControl.GuideCtrl.ShowGuide({
//                         callBack: function () {
//                             $playerDataManager.PlayerDataMgr.SetGuideIndex(
//                                 $const_Common.GuideName.仓库升级,
//                                 $const_Common.UpEquipLevelGuideIndex.引导点击升级3
//                             );
//                             t.getComponent($item_Bag_EquipItem.default).OpenInfo();
//                         },
//                         wPos: o,
//                         size: n
//                     });
//                 }
//             } else {
//                 if (
//                     $playerDataManager.PlayerDataMgr.GetGuideIndexByTaskName($const_Common.GuideName.水果上阵) ==
//                     $const_Common.DressUpEquipGuideIndex.选择水果
//                 ) {
//                     e.scheduleOnce(function () {
//                         var t = e.auto_ui.node_unLockFather.children[0];
//                         if (t) {
//                             var o = t.convertToWorldSpaceAR(cc.v2(0, 0));
//                             var n = cc.size(t.width, t.height);
//                             $guideControl.GuideCtrl.ShowGuide({
//                                 callBack: function () {
//                                     $playerDataManager.PlayerDataMgr.SetGuideIndex(
//                                         $const_Common.GuideName.水果上阵,
//                                         $const_Common.DressUpEquipGuideIndex.引导穿戴
//                                     );
//                                     t.getComponent($item_Bag_EquipItem.default).OpenInfo();
//                                 },
//                                 wPos: o,
//                                 size: n
//                             });
//                         }
//                     }, 0.15);
//                 } else {
//                     e.AICheck();
//                 }
//             }
//         });
//     };
//     o.prototype.hide = function () {};
//     o.prototype.onEnable = function () {
//         if ($hallGlobalVariable.default.isNeedResetWareHouse && this.upLevelMap) {
//             this.ResetThis();
//         }
//     };
//     o.prototype.ResetThis = function () {
//         $hallGlobalVariable.default.isNeedResetWareHouse = !1;
//         this.ShowDragView(!1);
//         this.ResetDressUp();
//         this.ResetUnLock();
//         this.AICheck();
//         this.ResetLock();
//     };
//     o.prototype.StartSet = function () {
//         var e = this;
//         if (!this.upLevelMap) {
//             this.shuiGuoArray = [];
//             $excel.Excel.shuiguo_all.forEach(function (t) {
//                 if (-1 != t.isShow) {
//                     e.shuiGuoArray.push(t);
//                 }
//             });
//             this.upLevelMap = new Map();
//             $excel.Excel.shuiguo_all.forEach(function (t) {
//                 if (-1 != t.isShow) {
//                     e.upLevelMap.set(t.id, []);
//                 }
//             });
//             $excel.Excel.shuiguolevel_all.forEach(function (t) {
//                 e.upLevelMap.get(t.shuiguoId).push(t);
//             });
//         }
//         this.ShowDragView(!1);
//         this.ResetDressUp();
//         this.ResetUnLock();
//         this.ResetLock();
//     };
//     o.prototype.ResetDressUp = function () {
//         this.auto_ui.node_dressupFather.children.forEach(function (e) {
//             e.active = !1;
//         });
//         var e = 0;
//         var t = $playerDataManager.PlayerDataMgr.dressUpArray;
//         var o = $excel.Excel.wareHouseControl(1).unLockArray;
//         for (var n = 0; n < t.length; n++) {
//             var i = t[n];
//             var a = void 0;
//             if (n < this.auto_ui.node_dressupFather.childrenCount) {
//                 a = this.auto_ui.node_dressupFather.children[n];
//             } else {
//                 (a = cc.instantiate(this.equipItem)).parent = this.auto_ui.node_dressupFather;
//             }
//             a.active = !0;
//             var r = a.getComponent($item_Bag_EquipItem.default);
//             var c = new $const_Hall.BagEquipShowData();
//             c.shuiGuoId = i;
//             if (-1 == i) {
//                 c.unLockChar = o[n];
//             }
//             if (i > 0) {
//                 e++;
//                 c.upLevelDatas = this.upLevelMap.get(i);
//             }
//             r.StartSet(c);
//         }
//         this.auto_ui.txt_allCountLabel.string = e + "/" + t.length;
//     };
//     o.prototype.ResetUnLock = function () {
//         this.auto_ui.node_unLockFather.children.forEach(function (e) {
//             e.active = !1;
//         });
//         this.shuiGuoArray.sort(function (e, t) {
//             return t.quality - e.quality;
//         });
//         var e = $playerDataManager.PlayerDataMgr.dressUpArray;
//         var t = 0;
//         for (var o = 0; o < this.shuiGuoArray.length; o++) {
//             var n = this.shuiGuoArray[o].id;
//             if ($playerDataManager.PlayerDataMgr.GetEquipDataById(n).isUnLock && -1 == e.indexOf(n)) {
//                 var i = void 0;
//                 if (t < this.auto_ui.node_unLockFather.childrenCount) {
//                     i = this.auto_ui.node_unLockFather.children[t];
//                 } else {
//                     (i = cc.instantiate(this.equipItem)).parent = this.auto_ui.node_unLockFather;
//                 }
//                 i.active = !0;
//                 var a = i.getComponent($item_Bag_EquipItem.default);
//                 var r = new $const_Hall.BagEquipShowData();
//                 r.shuiGuoId = n;
//                 r.upLevelDatas = this.upLevelMap.get(n);
//                 a.StartSet(r);
//                 t++;
//             }
//         }
//         this.auto_ui.node_unLockFather.active = t > 0;
//         this.auto_ui.node_unLockFather.parent.getChildByName("已解锁").active = t > 0;
//     };
//     o.prototype.ResetLock = function () {
//         this.auto_ui.node_lockFather.children.forEach(function (e) {
//             e.active = !1;
//         });
//         var e = 0;
//         var t = [];
//         for (var o = 0; o < this.shuiGuoArray.length; o++) {
//             var n = (i = this.shuiGuoArray[o]).id;
//             if (!$playerDataManager.PlayerDataMgr.GetEquipDataById(n).isUnLock) {
//                 t.push(i);
//             }
//         }
//         t.sort(function (e, t) {
//             return e.unLock - t.unLock;
//         });
//         for (o = 0; o < t.length; o++) {
//             var i = t[o];
//             var a = void 0;
//             if (e < this.auto_ui.node_lockFather.childrenCount) {
//                 a = this.auto_ui.node_lockFather.children[e];
//             } else {
//                 (a = cc.instantiate(this.equipItem)).parent = this.auto_ui.node_lockFather;
//             }
//             a.active = !0;
//             var r = a.getComponent($item_Bag_EquipItem.default);
//             var c = new $const_Hall.BagEquipShowData();
//             c.shuiGuoId = i.id;
//             c.upLevelDatas = this.upLevelMap.get(i.id);
//             r.StartSet(c);
//             e++;
//         }
//         this.auto_ui.node_lockFather.active = e > 0;
//         this.auto_ui.node_lockFather.parent.getChildByName("未解锁").active = e > 0;
//     };
//     o.prototype.ShowDrag = function (e) {
//         this.ShowDragView(!0);
//         if (!this.dragnode) {
//             this.dragnode = cc.instantiate(this.equipItem);
//             this.dragnode.parent = this.auto_ui.node_dragFather;
//             this.dragnode.setPosition(0, 0);
//             this.auto_ui.node_dragFather
//                 .addComponent($logic_ChildMoveEvent.default)
//                 .StartSet(
//                     this.onChildTouchStart.bind(this),
//                     this.onChildTouchMove.bind(this),
//                     this.onChildTouchUp.bind(this)
//                 );
//             this.auto_ui.node_clickCardNode
//                 .addComponent($logic_ChildMoveEvent.default)
//                 .StartSet(
//                     this.onChildTouchStart.bind(this),
//                     this.onChildTouchMove.bind(this),
//                     this.onChildTouchUp.bind(this)
//                 );
//             this.dragStartPos = this.auto_ui.node_dragFather.getPosition();
//         }
//         this.dragnode.active = !0;
//         var t = new $const_Hall.BagEquipShowData();
//         t.shuiGuoId = e;
//         t.upLevelDatas = this.upLevelMap.get(e);
//         this.dragnode.getComponent($item_Bag_EquipItem.default).StartSet(t, !1);
//         this.dragShuiGuoId = e;
//         if ($aIControl.default._instance.isOpen) {
//             this.ChangeOne();
//         }
//     };
//     o.prototype.onChildTouchStart = function (e) {
//         if (e.target == this.auto_ui.node_dragFather) {
//             this.auto_ui.node_dragFather.setPosition(
//                 this.auto_ui.node_dragFather.parent.convertToNodeSpaceAR(e.getLocation())
//             );
//         }
//     };
//     o.prototype.onChildTouchMove = function (e) {
//         if (e.target == this.auto_ui.node_dragFather) {
//             this.auto_ui.node_dragFather.setPosition(
//                 this.auto_ui.node_dragFather.parent.convertToNodeSpaceAR(e.getLocation())
//             );
//         }
//     };
//     o.prototype.onChildTouchUp = function (e) {
//         var t = this.auto_ui.node_dressupFather.convertToNodeSpaceAR(e.getLocation());
//         for (var o = 0; o < this.auto_ui.node_dressupFather.children.length; o++) {
//             var n = this.auto_ui.node_dressupFather.children[o];
//             if (cc.Vec2.distance(t, n.getPosition()) < 100) {
//                 var i = n.getComponent($item_Bag_EquipItem.default);
//                 if (-1 == $playerDataManager.PlayerDataMgr.globalData.dressUpArray[o]) {
//                     break;
//                 }
//                 if (i.openData.shuiGuoId > 0) {
//                     $playerDataManager.PlayerDataMgr.RemoveDressUpEquip(i.openData.shuiGuoId, o);
//                 }
//                 $playerDataManager.PlayerDataMgr.AddDressUpEquip(this.dragShuiGuoId, o);
//                 $eventManager.EventMgr.dispatchEvent(
//                     $evenType.EVENT_TYPE.MainRedPointChange,
//                     $redPointControl.RedPointType.upEquip
//                 );
//                 this.ResetDressUp();
//                 this.ResetUnLock();
//                 this.ShowDragView(!1);
//                 break;
//             }
//         }
//         if (e.target == this.auto_ui.node_dragFather) {
//             this.auto_ui.node_dragFather.setPosition(this.dragStartPos);
//         }
//     };
//     o.prototype.RemoveHero = function (e) {
//         if (e > 0) {
//             $playerDataManager.PlayerDataMgr.RemoveDressUpEquip(e);
//         }
//         this.ResetDressUp();
//         this.ResetUnLock();
//     };
//     o.prototype.ShowDragView = function (e) {
//         this.auto_ui.node_scrollView.active = !e;
//         this.auto_ui.node_dragView.active = e;
//         this.auto_ui.node_clickCardNode.active = e;
//         this.ShowScaleTween(e);
//     };
//     o.prototype.ShowScaleTween = function (e) {
//         this.auto_ui.node_dressupFather.children.forEach(function (t) {
//             t.stopAllActions();
//             t.scale = 1;
//             if (e) {
//                 t.runAction(cc.repeatForever(cc.sequence(cc.scaleTo(0.8, 1.1, 1.1), cc.scaleTo(0.8, 0.9, 0.9))));
//             }
//         });
//     };
//     o.prototype.EventResetAI = function () {
//         var e = this;
//         $eventManager.EventMgr.dispatchEvent(
//             $evenType.EVENT_TYPE.MainRedPointChange,
//             $redPointControl.RedPointType.upEquip
//         );
//         this.scheduleOnce(function () {
//             e.AICheck();
//         }, $aIControl.default._instance.aiCDTime);
//     };
//     o.prototype.AICheck = function () {
//         var e = this;
//         if ($aIControl.default._instance.isOpen) {
//             this.scheduleOnce(function () {
//                 if (e.CheckIsNeedDressUp()) {
//                     e.DressUpOne();
//                 } else {
//                     if (!e.UpOneLevel()) {
//                         $aIControl.default._instance.ShowClickBtn(
//                             $uI_Hall.default._instance.auto_ui.btn_fightingBtn.node,
//                             function () {
//                                 $uI_Hall.default._instance.ShowViewByType(2);
//                             }
//                         );
//                     }
//                 }
//             });
//         }
//     };
//     o.prototype.CheckIsNeedDressUp = function () {
//         var e = $playerDataManager.PlayerDataMgr.dressUpArray.filter(function (e) {
//             return 0 == e;
//         });
//         if (e && e.length > 0) {
//             this.aiCurrUnLockArray = [];
//             var t = 0;
//             var o = null;
//             for (var n = 0; n < this.auto_ui.node_unLockFather.children.length; n++) {
//                 var i = this.auto_ui.node_unLockFather.children[n];
//                 var a = $excel.Excel.shuiguo(i.getComponent($item_Bag_EquipItem.default).openData.shuiGuoId);
//                 if (a.quality > t) {
//                     o = a;
//                     t = a.quality;
//                 }
//             }
//             this.aiCurrUnLockArray = [o];
//             return !0;
//         }
//         this.aiCurrDressUpArray = [];
//         this.aiCurrUnLockArray = [];
//         this.shuiGuoArray.sort(function (e, t) {
//             return t.quality - e.quality;
//         });
//         var r = $playerDataManager.PlayerDataMgr.dressUpArray;
//         for (n = 0; n < this.shuiGuoArray.length; n++) {
//             var c = (i = this.shuiGuoArray[n]).id;
//             if ($playerDataManager.PlayerDataMgr.GetEquipDataById(c).isUnLock) {
//                 -1 == r.indexOf(c) ? this.aiCurrUnLockArray.push(i) : this.aiCurrDressUpArray.push(i);
//             }
//         }
//         return this.aiCurrDressUpArray[this.aiCurrDressUpArray.length - 1].quality < this.aiCurrUnLockArray[0].quality;
//     };
//     o.prototype.DressUpOne = function () {
//         var t = function (e) {
//             var t = o.auto_ui.node_unLockFather.children[e];
//             if (t.getComponent($item_Bag_EquipItem.default).openData.shuiGuoId == o.aiCurrUnLockArray[0].id) {
//                 $aIControl.default._instance.ShowClickBtn(t, function () {
//                     t.getComponent($item_Bag_EquipItem.default).OpenInfo(!0);
//                 });
//                 return {
//                     value: void 0
//                 };
//             }
//         };
//         var o = this;
//         for (var n = 0; n < this.auto_ui.node_unLockFather.children.length; n++) {
//             var i = t(n);
//             if ("object" == typeof i) {
//                 return i.value;
//             }
//         }
//     };
//     o.prototype.ChangeOne = function () {
//         var t = this;
//         var o = function (e) {
//             var o = n.auto_ui.node_dressupFather.children[e];
//             if (
//                 o.getComponent($item_Bag_EquipItem.default).openData.shuiGuoId ==
//                 n.aiCurrDressUpArray[n.aiCurrDressUpArray.length - 1].id
//             ) {
//                 var i = o.getComponent($item_Bag_EquipItem.default);
//                 if (-1 == $playerDataManager.PlayerDataMgr.globalData.dressUpArray[e]) {
//                     return "break";
//                 } else {
//                     return (
//                         $aIControl.default._instance.ShowClickBtn(o, function () {
//                             if (i.openData.shuiGuoId > 0) {
//                                 $playerDataManager.PlayerDataMgr.RemoveDressUpEquip(i.openData.shuiGuoId, e);
//                             }
//                             $playerDataManager.PlayerDataMgr.AddDressUpEquip(t.dragShuiGuoId, e);
//                             t.ResetDressUp();
//                             t.ResetUnLock();
//                             t.ShowDragView(!1);
//                             t.AICheck();
//                         }),
//                         {
//                             value: void 0
//                         }
//                     );
//                 }
//             }
//         };
//         var n = this;
//         for (var i = 0; i < this.auto_ui.node_dressupFather.children.length; i++) {
//             var a = o(i);
//             if ("object" == typeof a) {
//                 return a.value;
//             }
//             if ("break" === a) {
//                 break;
//             }
//         }
//     };
//     o.prototype.UpOneLevel = function () {
//         function e(e) {
//             $aIControl.default._instance.ShowClickBtn(e.node, function () {
//                 e.OpenInfo();
//             });
//         }
//         for (var t = 0; t < this.auto_ui.node_dressupFather.children.length; t++) {
//             if (
//                 (o = this.auto_ui.node_dressupFather.children[t].getComponent($item_Bag_EquipItem.default)).GetCanUp()
//             ) {
//                 e(o);
//                 return !0;
//             }
//         }
//         for (t = 0; t < this.auto_ui.node_unLockFather.children.length; t++) {
//             var o;
//             if ((o = this.auto_ui.node_unLockFather.children[t].getComponent($item_Bag_EquipItem.default)).GetCanUp()) {
//                 e(o);
//                 return !0;
//             }
//         }
//         return !1;
//     };
//     __decorate([E($module_WareHouse_UIBindings.default)], o.prototype, "auto_ui", void 0);
//     __decorate([E(cc.Prefab)], o.prototype, "equipItem", void 0);
//     return __decorate([M], o);
// })($baseModule.default);
// exports.default = C;


import { EventMgrInstance } from './EventManager';
import ModuleWareHouseUIBindings from './Module_WareHouse_UIBindings';
import AICtrl from './AIControl';
import { GuideCtrlInstance } from './GuideControl';
import { RedPointType } from './RedPointControl';
import { EVENT_TYPE } from './EvenType';
import { PlayerDataMgr } from './PlayerDataManager';
import { Excel } from './Excel';
import LogicChildMoveEvent from './Logic_ChildMoveEvent';
import FruitDataManager from './HallGlobalVariable';
import ItemBagEquipItem from './Item_Bag_EquipItem';
import ViewHall from './UI_Hall';
import BaseModule from './BaseModule';
import { GuideName, UpEquipLevelGuideIndex, DressUpEquipGuideIndex } from './Const_Common';
import { BagEquipShowData } from './Const_Hall';

const { ccclass, property, inspector } = cc._decorator;

/**
 * 建议类名：WarehouseManager
 */
@ccclass
class ModuleWareHouse extends BaseModule {
    @property(ModuleWareHouseUIBindings)
    auto_ui: ModuleWareHouseUIBindings = null;

    @property(cc.Prefab)
    equipItem: cc.Prefab = null;

    private dragnode: cc.Node = null;
    private dragStartPos: cc.Vec2 = null;
    private dragShuiGuoId: number = null;
    private shuiGuoArray: any[] = [];
    private upLevelMap: Map<number, any[]> = null;
    private aiCurrUnLockArray: any[] = [];
    private aiCurrDressUpArray: any[] = [];

    onLoad() {
        EventMgrInstance.addListener(EVENT_TYPE.HallBagShowDrag, this.showDrag, this);
        EventMgrInstance.addListener(EVENT_TYPE.HallBagRemoveId, this.removeHero, this);
        EventMgrInstance.addListener(EVENT_TYPE.HallResetBag, this.resetThis, this);
        EventMgrInstance.addListener(EVENT_TYPE.ResetWareHouseAI, this.resetAIEvent, this);
    }

    onDestroy() {
        super.onDestroy();
        EventMgrInstance.removeListener(EVENT_TYPE.HallBagShowDrag, this.showDrag, this);
        EventMgrInstance.removeListener(EVENT_TYPE.HallBagRemoveId, this.removeHero, this);
        EventMgrInstance.removeListener(EVENT_TYPE.HallResetBag, this.resetThis, this);
        EventMgrInstance.removeListener(EVENT_TYPE.ResetWareHouseAI, this.resetAIEvent, this);
    }

    /**
     * 显示方法
     * 建议方法名：display
     */
    show() {
        this.initialize();
        this.scheduleOnce(() => {
            if (
                PlayerDataMgr.getGuideIndexByTaskName(GuideName.EquipLevelUp) ==
                UpEquipLevelGuideIndex.GuideClickWarehouseFruit2
            ) {
                const firstChild = this.auto_ui.node_dressupFather.children[0];
                if (firstChild) {
                    const worldPos = firstChild.convertToWorldSpaceAR(cc.v2(0, 0));
                    const size = cc.size(firstChild.width, firstChild.height);
                    GuideCtrlInstance.showGuide({
                        callBack: () => {
                            PlayerDataMgr.setGuideIndex(
                                GuideName.EquipLevelUp,
                                UpEquipLevelGuideIndex.GuideClickUpgrade3
                            );
                            firstChild.getComponent(ItemBagEquipItem).openInfo();
                        },
                        wPos: worldPos,
                        size: size
                    });
                }
            } else if (
                PlayerDataMgr.getGuideIndexByTaskName(GuideName.FruitDressUpEquip) ==
                DressUpEquipGuideIndex.SelectFruit
            ) {
                this.scheduleOnce(() => {
                    const firstChild = this.auto_ui.node_unLockFather.children[0];
                    if (firstChild) {
                        const worldPos = firstChild.convertToWorldSpaceAR(cc.v2(0, 0));
                        const size = cc.size(firstChild.width, firstChild.height);
                        GuideCtrlInstance.showGuide({
                            callBack: () => {
                                PlayerDataMgr.setGuideIndex(
                                    GuideName.FruitDressUpEquip,
                                    DressUpEquipGuideIndex.GuideDressing
                                );
                                firstChild.getComponent(ItemBagEquipItem).openInfo();
                            },
                            wPos: worldPos,
                            size: size
                        });
                    }
                }, 0.15);
            } else {
                this.checkAI();
            }
        });
    }

    hide() { }

    onEnable() {
        if (FruitDataManager.isNeedResetWareHouse && this.upLevelMap) {
            this.resetThis();
        }
    }

    /**
     * 重置方法
     * 建议方法名：reset
     */
    resetThis() {
        FruitDataManager.isNeedResetWareHouse = false;
        this.ShowDragView(false);
        this.resetDressUp();
        this.resetUnLock();
        this.checkAI();
        this.resetLock();
    }

    /**
     * 开始设置方法
     * 建议方法名：initialize
     */
    initialize() {
        if (!this.upLevelMap) {
            this.shuiGuoArray = [];
            Excel.shuiguo_all.forEach((item) => {
                if (item.isShow !== -1) {
                    this.shuiGuoArray.push(item);
                }
            });
            this.upLevelMap = new Map();
            Excel.shuiguo_all.forEach((item) => {
                if (item.isShow !== -1) {
                    this.upLevelMap.set(item.id, []);
                }
            });
            Excel.shuiguolevel_all.forEach((item) => {
                this.upLevelMap.get(item.shuiguoId).push(item);
            });
        }
        this.ShowDragView(false);
        this.resetDressUp();
        this.resetUnLock();
        this.resetLock();
    }

    /**
     * 重置穿戴方法
     * 建议方法名：resetDressUp
     */
    resetDressUp() {
        this.auto_ui.node_dressupFather.children.forEach((child) => {
            child.active = false;
        });
        let activeCount = 0;
        const dressUpArray = PlayerDataMgr.dressUpArray;
        const unLockArray = Excel.wareHouseControl(1).unLockArray;
        for (let i = 0; i < dressUpArray.length; i++) {
            const dressUpId = dressUpArray[i];
            let childNode;
            if (i < this.auto_ui.node_dressupFather.childrenCount) {
                childNode = this.auto_ui.node_dressupFather.children[i];
            } else {
                childNode = cc.instantiate(this.equipItem);
                childNode.parent = this.auto_ui.node_dressupFather;
            }
            childNode.active = true;
            const equipItemComponent:ItemBagEquipItem = childNode.getComponent(ItemBagEquipItem);
            const bagEquipShowData = new BagEquipShowData();
            bagEquipShowData.shuiGuoId = dressUpId;
            if (dressUpId === -1) {
                bagEquipShowData.unLockChar = unLockArray[i];
            }
            if (dressUpId > 0) {
                activeCount++;
                bagEquipShowData.upLevelDatas = this.upLevelMap.get(dressUpId);
            }
            equipItemComponent.startSet(bagEquipShowData);
        }
        this.auto_ui.txt_allCountLabel.string = `${activeCount}/${dressUpArray.length}`;
    }

    /**
     * 重置解锁方法
     * 建议方法名：resetUnlock
     */
    resetUnLock() {
        this.auto_ui.node_unLockFather.children.forEach((child) => {
            child.active = false;
        });
        this.shuiGuoArray.sort((a, b) => b.quality - a.quality);
        const dressUpArray = PlayerDataMgr.dressUpArray;
        let activeCount = 0;
        for (let i = 0; i < this.shuiGuoArray.length; i++) {
            const shuiGuoId = this.shuiGuoArray[i].id;
            if (PlayerDataMgr.getEquipDataById(shuiGuoId).isUnLock && dressUpArray.indexOf(shuiGuoId) === -1) {
                let childNode;
                if (activeCount < this.auto_ui.node_unLockFather.childrenCount) {
                    childNode = this.auto_ui.node_unLockFather.children[activeCount];
                } else {
                    childNode = cc.instantiate(this.equipItem);
                    childNode.parent = this.auto_ui.node_unLockFather;
                }
                childNode.active = true;
                const equipItemComponent:ItemBagEquipItem = childNode.getComponent(ItemBagEquipItem);
                const bagEquipShowData = new BagEquipShowData();
                bagEquipShowData.shuiGuoId = shuiGuoId;
                bagEquipShowData.upLevelDatas = this.upLevelMap.get(shuiGuoId);
                equipItemComponent.startSet(bagEquipShowData);
                activeCount++;
            }
        }
        this.auto_ui.node_unLockFather.active = activeCount > 0;
        this.auto_ui.node_unLockFather.parent.getChildByName("已解锁").active = activeCount > 0;
    }

    /**
     * 重置锁定方法
     * 建议方法名：resetLock
     */
    resetLock() {
        this.auto_ui.node_lockFather.children.forEach((child) => {
            child.active = false;
        });
        let activeCount = 0;
        const lockedItems = [];
        for (let i = 0; i < this.shuiGuoArray.length; i++) {
            const item = this.shuiGuoArray[i];
            const shuiGuoId = item.id;
            if (!PlayerDataMgr.getEquipDataById(shuiGuoId).isUnLock) {
                lockedItems.push(item);
            }
        }
        lockedItems.sort((a, b) => a.unLock - b.unLock);
        for (let i = 0; i < lockedItems.length; i++) {
            const item = lockedItems[i];
            let childNode;
            if (activeCount < this.auto_ui.node_lockFather.childrenCount) {
                childNode = this.auto_ui.node_lockFather.children[activeCount];
            } else {
                childNode = cc.instantiate(this.equipItem);
                childNode.parent = this.auto_ui.node_lockFather;
            }
            childNode.active = true;
            const equipItemComponent:ItemBagEquipItem = childNode.getComponent(ItemBagEquipItem);
            const bagEquipShowData = new BagEquipShowData();
            bagEquipShowData.shuiGuoId = item.id;
            bagEquipShowData.upLevelDatas = this.upLevelMap.get(item.id);
            equipItemComponent.startSet(bagEquipShowData);
            activeCount++;
        }
        this.auto_ui.node_lockFather.active = activeCount > 0;
        this.auto_ui.node_lockFather.parent.getChildByName("未解锁").active = activeCount > 0;
    }

    /**
     * 显示拖拽方法
     * 建议方法名：displayDrag
     */
    showDrag(shuiGuoId: number) {
        this.ShowDragView(true);
        if (!this.dragnode) {
            this.dragnode = cc.instantiate(this.equipItem);
            this.dragnode.parent = this.auto_ui.node_dragFather;
            this.dragnode.setPosition(0, 0);
            this.auto_ui.node_dragFather
                .addComponent(LogicChildMoveEvent)
                .startSet(
                    this.onChildTouchStart.bind(this),
                    this.onChildTouchMove.bind(this),
                    this.onChildTouchUp.bind(this)
                );
            this.auto_ui.node_clickCardNode
                .addComponent(LogicChildMoveEvent)
                .startSet(
                    this.onChildTouchStart.bind(this),
                    this.onChildTouchMove.bind(this),
                    this.onChildTouchUp.bind(this)
                );
            this.dragStartPos = this.auto_ui.node_dragFather.getPosition();
        }
        this.dragnode.active = true;
        const bagEquipShowData = new BagEquipShowData();
        bagEquipShowData.shuiGuoId = shuiGuoId;
        bagEquipShowData.upLevelDatas = this.upLevelMap.get(shuiGuoId);
        this.dragnode.getComponent(ItemBagEquipItem).startSet(bagEquipShowData, false);
        this.dragShuiGuoId = shuiGuoId;
        if (AICtrl._instance.isOpen) {
            this.changeOneItem();
        }
    }

    onChildTouchStart(event: cc.Event.EventTouch) {
        if (event.target === this.auto_ui.node_dragFather) {
            this.auto_ui.node_dragFather.setPosition(
                this.auto_ui.node_dragFather.parent.convertToNodeSpaceAR(event.getLocation())
            );
        }
    }

    onChildTouchMove(event: cc.Event.EventTouch) {
        if (event.target === this.auto_ui.node_dragFather) {
            this.auto_ui.node_dragFather.setPosition(
                this.auto_ui.node_dragFather.parent.convertToNodeSpaceAR(event.getLocation())
            );
        }
    }

    onChildTouchUp(event: cc.Event.EventTouch) {
        const localPos = this.auto_ui.node_dressupFather.convertToNodeSpaceAR(event.getLocation());
        for (let i = 0; i < this.auto_ui.node_dressupFather.children.length; i++) {
            const child = this.auto_ui.node_dressupFather.children[i];
            if (cc.Vec2.distance(localPos, child.getPosition()) < 100) {
                const equipItemComponent = child.getComponent(ItemBagEquipItem);
                if (PlayerDataMgr.globalData.dressUpArray[i] === -1) {
                    break;
                }
                if (equipItemComponent.openData.shuiGuoId > 0) {
                    PlayerDataMgr.removeDressUpEquip(equipItemComponent.openData.shuiGuoId, i);
                }
                PlayerDataMgr.addDressUpEquip(this.dragShuiGuoId, i);
                EventMgrInstance.emitEvent(
                    EVENT_TYPE.MainRedPointChange,
                    RedPointType.upEquip
                );
                this.resetDressUp();
                this.resetUnLock();
                this.ShowDragView(false);
                break;
            }
        }
        if (event.target === this.auto_ui.node_dragFather) {
            this.auto_ui.node_dragFather.setPosition(this.dragStartPos);
        }
    }

    /**
     * 移除英雄方法
     * 建议方法名：removeHero
     */
    removeHero(shuiGuoId: number) {
        if (shuiGuoId > 0) {
            PlayerDataMgr.removeDressUpEquip(shuiGuoId);
        }
        this.resetDressUp();
        this.resetUnLock();
    }

    /**
     * 显示拖拽视图方法
     * 建议方法名：displayDragView
     */
    ShowDragView(isVisible: boolean) {
        this.auto_ui.node_scrollView.active = !isVisible;
        this.auto_ui.node_dragView.active = isVisible;
        this.auto_ui.node_clickCardNode.active = isVisible;
        this.showScaleTween(isVisible);
    }

    /**
     * 显示缩放动画方法
     * 建议方法名：displayScaleTween
     */
    showScaleTween(isVisible: boolean) {
        this.auto_ui.node_dressupFather.children.forEach((child) => {
            child.stopAllActions();
            child.scale = 1;
            if (isVisible) {
                child.runAction(cc.repeatForever(cc.sequence(cc.scaleTo(0.8, 1.1, 1.1), cc.scaleTo(0.8, 0.9, 0.9))));
            }
        });
    }

    /**
     * 重置AI事件方法
     * 建议方法名：resetAIEvent
     */
    resetAIEvent() {
        EventMgrInstance.emitEvent(
            EVENT_TYPE.MainRedPointChange,
            RedPointType.upEquip
        );
        this.scheduleOnce(() => {
            this.checkAI();
        }, AICtrl._instance.aiCDTime);
    }

    /**
     * AI检查方法
     * 建议方法名：checkAI
     */
    checkAI() {
        if (AICtrl._instance.isOpen) {
            this.scheduleOnce(() => {
                if (this.checkNeedDressUp()) {
                    this.dressUpOneItem();
                } else if (!this.upgradeOneItem()) {
                    AICtrl._instance.displayClickButton(
                        ViewHall._instance.auto_ui.btn_fightingBtn.node,
                        () => {
                            ViewHall._instance.showViewByType(2);
                        }
                    );
                }
            });
        }
    }

    /**
     * 检查是否需要穿戴方法
     * 建议方法名：checkNeedDressUp
     */
    checkNeedDressUp(): boolean {
        const emptyDressUpSlots = PlayerDataMgr.dressUpArray.filter((id) => id === 0);
        if (emptyDressUpSlots.length > 0) {
            this.aiCurrUnLockArray = [];
            let highestQuality = 0;
            let bestItem = null;
            for (let i = 0; i < this.auto_ui.node_unLockFather.children.length; i++) {
                const child = this.auto_ui.node_unLockFather.children[i];
                const itemData = Excel.shuiguo(child.getComponent(ItemBagEquipItem).openData.shuiGuoId);
                if (itemData.quality > highestQuality) {
                    bestItem = itemData;
                    highestQuality = itemData.quality;
                }
            }
            this.aiCurrUnLockArray = [bestItem];
            return true;
        }
        this.aiCurrDressUpArray = [];
        this.aiCurrUnLockArray = [];
        this.shuiGuoArray.sort((a, b) => b.quality - a.quality);
        const dressUpArray = PlayerDataMgr.dressUpArray;
        for (let i = 0; i < this.shuiGuoArray.length; i++) {
            const item = this.shuiGuoArray[i];
            const shuiGuoId = item.id;
            if (PlayerDataMgr.getEquipDataById(shuiGuoId).isUnLock) {
                if (dressUpArray.indexOf(shuiGuoId) === -1) {
                    this.aiCurrUnLockArray.push(item);
                } else {
                    this.aiCurrDressUpArray.push(item);
                }
            }
        }
        return this.aiCurrDressUpArray[this.aiCurrDressUpArray.length - 1].quality < this.aiCurrUnLockArray[0].quality;
    }

    /**
     * 穿戴一个物品方法
     * 建议方法名：dressUpOneItem
     */
    dressUpOneItem() {
        const findAndDressUp = (index: number) => {
            const child = this.auto_ui.node_unLockFather.children[index];
            if (child.getComponent(ItemBagEquipItem).openData.shuiGuoId === this.aiCurrUnLockArray[0].id) {
                AICtrl._instance.displayClickButton(child, () => {
                    child.getComponent(ItemBagEquipItem).openInfo(true);
                });
                return { value: undefined };
            }
        };

        for (let i = 0; i < this.auto_ui.node_unLockFather.children.length; i++) {
            const result = findAndDressUp(i);
            if (result) {
                return result.value;
            }
        }
    }

    /**
     * 更换一个物品方法
     * 建议方法名：changeOneItem
     */
    changeOneItem() {
        const findAndChange = function (index: number) {
            var child = this.auto_ui.node_dressupFather.children[index];
            if (
                child.getComponent(ItemBagEquipItem).openData.shuiGuoId ==
                this.aiCurrDressUpArray[this.aiCurrDressUpArray.length - 1].id
            ) {
                var i = child.getComponent(ItemBagEquipItem);
                if (-1 == PlayerDataMgr.globalData.dressUpArray[index]) {
                    return "break";
                } else {
                    return (
                        AICtrl._instance.displayClickButton(child, function () {
                            if (i.openData.shuiGuoId > 0) {
                                PlayerDataMgr.removeDressUpEquip(i.openData.shuiGuoId, index);
                            }
                            PlayerDataMgr.addDressUpEquip(this.dragShuiGuoId, index);
                            this.ResetDressUp();
                            this.ResetUnLock();
                            this.ShowDragView(false);
                            this.AICheck();
                        }),
                        {
                            value: void 0
                        }
                    );
                }
            }
        };
        for (let i = 0; i < this.auto_ui.node_dressupFather.children.length; i++) {
            const result = findAndChange(i);
            if ("object" == typeof result) {
                return result.value;
            }
            if ("break" === result) {
                break;
            }
        }
    }

    /**
     * 升级一个物品方法
     * 建议方法名：upgradeOneItem
     */
    upgradeOneItem(): boolean {
        const tryUpgrade = (equipItemComponent: ItemBagEquipItem) => {
            AICtrl._instance.displayClickButton(equipItemComponent.node, () => {
                equipItemComponent.openInfo();
            });
        };

        for (let i = 0; i < this.auto_ui.node_dressupFather.children.length; i++) {
            const equipItemComponent = this.auto_ui.node_dressupFather.children[i].getComponent(ItemBagEquipItem);
            if (equipItemComponent.canUpgrade()) {
                tryUpgrade(equipItemComponent);
                return true;
            }
        }

        for (let i = 0; i < this.auto_ui.node_unLockFather.children.length; i++) {
            const equipItemComponent = this.auto_ui.node_unLockFather.children[i].getComponent(ItemBagEquipItem);
            if (equipItemComponent.canUpgrade()) {
                tryUpgrade(equipItemComponent);
                return true;
            }
        }

        return false;
    }
}

export default ModuleWareHouse;